/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.ipfw.cs590.cheat.struts.actionforms;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

/**
 *
 * @author jmbaker
 */
public class LoginForm extends ActionForm {

    /**
     * Email
     */
    private String email;
    /**
     * Password
     */
    private String password;

    /**
     * Default constructor
     */
    public LoginForm() {
        super();
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param request The HTTP Request we are processing.
     * @return
     */
    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();

        //If the email isn't submitted or less than 5 in length
        if (getEmail() == null || getEmail().length() < 5) {
            errors.add("login", new ActionMessage("errors.login.required"));
        }

        //If the password isn't provided
        if (getPassword() == null || getPassword().length() < 1) {
            errors.add("password", new ActionMessage("errors.password.required"));
        }

        return errors;
    }
}
